home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / C / Applications / SML⁄NJ 93+ / Documentation / examples / missionaries / buffers.sml next >
Encoding:
Text File  |  1995-12-30  |  530 b   |  26 lines  |  [TEXT/R*ch]

  1. (* depth-first state buffer -- implements a stack *)
  2.  
  3. structure DF : BUFFER =
  4. struct
  5.   type 'a buffer = 'a list
  6.   exception EMPTY
  7.   val empty = []
  8.   fun get [] = raise EMPTY
  9.     | get(x::l) = (x,l)
  10.   fun put(x,l) = x::l
  11. end
  12.  
  13.  
  14. (* breadth-first state buffer -- implements an applicative queue *)
  15.  
  16. structure BF : BUFFER =
  17. struct
  18.   type 'a buffer = 'a list * 'a list
  19.   exception EMPTY
  20.   val empty = ([],[])
  21.   fun get([],[]) = raise EMPTY
  22.     | get(a::r,l) = (a,(r,l))
  23.     | get([],l) = get(rev l,[])
  24.   fun put(x,(m,l)) = (m,x::l)
  25. end
  26.